package cn.kxm.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.kxm.dao.DictMapper;
import cn.kxm.pojo.Dict;
import cn.kxm.pojo.DictDetail;
import cn.kxm.service.DictService;
@Service
public class DictServiceImpl implements DictService {
    @Autowired
	private DictMapper dictMapper;
	
    @Override
	public List<Dict> getDictListByType(String type) {
		return dictMapper.getDictListByType(type);
	}

	@Override
	public List<Dict> getDicts() {
		return dictMapper.getDicts();
	}

	@Override
	public int getDictId() {
		return dictMapper.getDictId();
	}

	@Override
	public int addDict(Dict dict) {
		return dictMapper.addDict(dict);
	}

	@Override
	public List<Map<String, Object>> getDictList(Integer dictValue,
			String dictKey, String dictType, Integer pageNo, Integer pageSize) {
		return dictMapper.getDictList(dictValue, dictKey, dictType, pageNo, pageSize);
	}

	@Override
	public int getDictCount(Integer dictValue, String dictKey, String dictType) {
		return dictMapper.getDictCount(dictValue, dictKey, dictType);
	}

	@Override
	public int addDictDetail(DictDetail dictDetail) {
		return dictMapper.addDictDetail(dictDetail);
	}

	@Override
	public String getDictByType(String dictType) {
		return dictMapper.getDictByType(dictType);
	}
	
	@Override
	public int addAllDict(Dict dict,DictDetail dictDetail){
		addDict(dict);
		int id=getDictId();
		dictDetail.setDid(id);
		addDictDetail(dictDetail);
		return 1;
	}

	@Override
	public Map<String, Object> getDictById(Integer id) {
		return dictMapper.getDictById(id);
	}

	@Override
	public int updateDict(Dict dict) {
		return dictMapper.updateDict(dict);
	}

	@Override
	public int updateDictDetail(DictDetail dictDetail) {
		return dictMapper.updateDictDetail(dictDetail);
	}
	
	@Override
	public int updateAllDict(Dict dict,DictDetail dictDetail){
		updateDict(dict);
		updateDictDetail(dictDetail);
		return 1;
	}

	@Override
	public Dict checkDictKey(String key) {
		return dictMapper.findDictByKey(key);
	}

	@Override
	public int delDict(Integer id) {
		return dictMapper.delDict(id);
	}

	@Override
	public int delDictDetail(Integer did) {
		return dictMapper.delDictDetail(did);
	}
	
	public int delOne(Integer id){
		delDict(id);
		delDictDetail(id);
		return 1;		
	}
}
